package com.atcumt.QiAnXin;

public class XYE {

    public static void main(String[] args) {
        String[] dates = { "20th Oct 2051", "20th Oct 2051", "29th Feb 2004", "2nd Jan 2022" };
        int res = dateArraysSum(dates);
        System.out.println(res);
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * 
     * ["20th Oct 2051","20th Oct 2051","29th Feb 2004","2nd Jan 2022"]
     * {“Jan"，"Feb"，"Mar"，"Apr”，"May"，"Jun"，"Jul"，"Aug"，"Sep"，"Oct"，"Nov"，"Dec"}
     * 日期字符串数组一年中的几天求和
     * 
     * @param dates string字符串一维数组 日期字符串数组
     * @return int整型
     */
    public static int dateArraysSum(String[] dates) {
        // write code here
        int sum = 0, dayNum, yearNum;
        for (int i = 0; i < dates.length; i++) {
            String[] date = dates[i].split(" ");
            String daystrs = date[0];
            String month = date[1];
            String yearStr = date[2];
            yearNum = Integer.parseInt(yearStr);
            if (daystrs.length() == 3) {
                String daystr = daystrs.substring(0, 1);
                dayNum = Integer.parseInt(daystr);
            } else {
                String daystr = daystrs.substring(0, 2);
                dayNum = Integer.parseInt(daystr);
            }

            switch (month) {
                case "Dec":
                    sum += 30;
                case "Nov":
                    sum += 31;
                case "Oct":
                    sum += 30;
                case "Sep":
                    sum += 31;
                case "Aug":
                    sum += 31;
                case "Jul":
                    sum += 30;
                case "Jun":
                    sum += 31;
                case "May":
                    sum += 30;
                case "Apr":
                    sum += 31;
                case "Mar":
                    if (yearNum % 4 == 0 && yearNum % 100 != 0 || yearNum % 400 == 0) {
                        sum += 29;
                    } else {
                        sum += 28;
                    }
                case "Feb":
                    sum += 31;
                case "Jan":
                    sum += 0;
            }
            sum += dayNum;
        }
        return sum;
    }
}
